package cn.com.dcsgo.library.admin.domain.vo;

import cn.com.dcsgo.library.admin.domain.po.BorrowRecord;
import cn.com.dcsgo.library.admin.domain.po.User;
import cn.com.dcsgo.library.admin.enums.BookStatus;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @author Dcsgo
 * @since 2024/9/4 11:49
 */
@Data
@ApiModel(description = "图书复本详情")
public class BookCopiesVO {
    @ApiModelProperty("复本编号")
    private Long copyId;

    @ApiModelProperty("借阅人")
    private String name;

    @ApiModelProperty("电话号码")
    private String phone;

    @ApiModelProperty("借阅日期")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy年M月d日 H:m:s")
    private LocalDateTime borrowDate;

    @ApiModelProperty("应还日期")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy年M月d日 H:m:s")
    private LocalDateTime dueDate;

    @ApiModelProperty("借阅状态")
    private BookStatus status;

    public static BookCopiesVO of(User user, BorrowRecord borrowRecord) {
        BookCopiesVO res = new BookCopiesVO();
        res.copyId = borrowRecord.getBookCopiesId();
        res.name = user.getName();
        res.phone = user.getPhone();
        res.borrowDate = borrowRecord.getBorrowDate();
        res.dueDate = borrowRecord.getDueDate();
        res.status = BookStatus.ofValue(borrowRecord.getStatus());
        return res;
    }

    public static BookCopiesVO of(Long copyId) {
        BookCopiesVO res = new BookCopiesVO();
        res.copyId = copyId;
        res.status = BookStatus.IN_PAVILION;
        return res;
    }
}
